package com.aly.game.exe2lua.enums;

import com.aly.game.exe2lua.funcs.Props;

/**
 * @author Aly on  2016-07-19.
 */
public enum FileFilterType {
    ALL("1") {
        @Override
        public boolean isParseFile(String fileName) {
            return true;
        }

        @Override
        public void init(Props props) {

        }
    },
    EXCLUDES("2") {
        @Override
        public boolean isParseFile(String fileName) {
            if (null != fileNames) {
                for (String exclude : fileNames) {
                    if (fileName.startsWith(exclude)) {
                        return false;
                    }
                }
            }
            return true;
        }

        @Override
        public void init(Props props) {
            fileNames = props.get("excludes").split(",");
        }
    },
    INCLUDES("3") {
        @Override
        public boolean isParseFile(String fileName) {
            return !EXCLUDES.isParseFile(fileName);
        }

        @Override
        public void init(Props props) {
            fileNames = props.get("includes").split(",");
        }
    },
    ;
    protected String[] fileNames;
    private String name;

    FileFilterType(String name) {
        this.name = name;
    }

    public static FileFilterType getType(String name) {
        for (FileFilterType fileFilterType : FileFilterType.values()) {
            if (fileFilterType.name.equals(name)) {
                return fileFilterType;
            }
        }
        return ALL;
    }

    public String[] getFileNames() {
        return fileNames;
    }

    public abstract boolean isParseFile(String fileName);

    public abstract void init(Props props);
}
